package com.xxy.springcloud.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @program: cloud2021
 * @description:
 * @author: 小小鱼
 * @date: 2021-03-11 20:05
 **/
@Service
@Slf4j
public class PaymentService {


    public String paymentInfo_Ok(Integer id){
        log.info(Thread.currentThread().getName());
        return Thread.currentThread().getName()+"打印了id:"+id+"哈哈～～～";
    }

    @HystrixCommand(
            commandKey = "paymentInfo",
            commandProperties = {
                    @HystrixProperty(name="execution.timeout.enabled", value="true"),
                    @HystrixProperty(name="execution.isolation.thread.timeoutInMilliseconds", value="3000"),
            },
            fallbackMethod = "paymentInfo_TimeOutHandle"
    )
    public String paymentInfo_TimeOut(Integer id){
        log.info(Thread.currentThread().getName());
        try{ Thread.sleep(4000); }catch (Exception e){e.printStackTrace();}
        return Thread.currentThread().getName()+"打印了id:"+id+"哈哈～～～";
    }

    public String paymentInfo_TimeOutHandle(Integer id){
        log.info(Thread.currentThread().getName());
        return Thread.currentThread().getName()+"打印了超时id:"+id+"哭～～～";
    }
}
